package org.fyp.synchrona.blog.communication;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;


import com.google.gdata.client.GoogleAuthTokenFactory;
import com.google.gdata.util.AuthenticationException;
import org.apache.http.client.HttpClient;
import org.apache.http.impl.client.DefaultHttpClient;


public class Communication {
	
	private String userName;
	
	private String password;
	
	private GoogleAuthTokenFactory factory;
	
	private String token;
	
	private String serviceUrl = "http://www.blogger.com/home";
	
	private String loginUrl;
	
	HttpClient httpclient ;
	
	public Communication(String userName, String password){
		this.userName = userName;
		this.password = password;
		factory = new GoogleAuthTokenFactory("blogger", "", null);
		try {
			token = factory.getAuthToken(this.userName, this.password, null, null,"blogger", "");
		} catch (AuthenticationException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		try {
			loginUrl = "https://www.blogger.com/start?continue="+ URLEncoder.encode(serviceUrl, "UTF-8") + "&auth=" + token;
		} catch (UnsupportedEncodingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		httpclient = new DefaultHttpClient();
	}
	
	public String getUserName(){
		return this.userName;
	}

	public String getPassword(){
		return this.password;
	}
	
	public String getToken(){
		return this.token;
	}
	
	public GoogleAuthTokenFactory getGoogleAuthTokenFactory(){
		return this.factory;
	}
	
	public String getServiceURL(){
		return this.serviceUrl;
	}
	
	public String getLoginURL(){
		return this.loginUrl;
	}
	
	public HttpClient getHttpClient(){
		return httpclient;
	}
}
